package com.star.jersey.example.esJob.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.dataflow.DataflowJob;
import com.star.jersey.esJob.annotation.ElasticJobConfig;
import com.star.jersey.example.esJob.pojo.Demo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zhouhengzhe
 * @description: 测试用例
 * @date 2022/10/17 2:32
 * @since v1
 */
@Slf4j
@Component
@ElasticJobConfig(
        name = "com.star.jersey.example.esJob.job.DemoDataflowJob",
        cron = "0/10 * * * * ?",
        description = "demo",
        overwrite = true,
        shardingTotalCount = 1
)
public class DemoDataflowJob implements DataflowJob<Demo> {

    /**
     * 从哪里抓数据
     *
     * @param shardingContext
     * @return
     */
    @Override
    public List<Demo> fetchData(ShardingContext shardingContext) {
        //处理业务数据流，返回数据，一个list
        return new ArrayList<Demo>() {{
            add(Demo.builder().demo("测试").build());
            add(Demo.builder().demo("测试1").build());
        }};
    }

    /**
     * 处理数据
     *
     * @param shardingContext 分片上下文
     * @param list            数据集合
     */
    @Override
    public void processData(ShardingContext shardingContext, List<Demo> list) {
        list.forEach(System.out::println);
    }
}
